// import redisDriver from "unstorage/drivers/redis";
import fsDriver from "unstorage/drivers/fs-lite";
import { createStorage } from "unstorage";
import mongodbDriver from "unstorage/drivers/mongodb";

export default defineNitroPlugin(() => {
  const storage = useStorage();
  const password = import.meta.env.MONGODB_PASSWORD;
  const uri = import.meta.env.MONGODB_URI;
  if (!(password && uri))
    console.error("MONGODB_SRC is not set in .env file");

  // Dynamically pass in credentials from runtime configuration, or other sources
  const driver = mongodbDriver({
    connectionString: `mongodb+srv://${password}@${uri}/?retryWrites=true&w=majority&appName=Cluster0`,
  });

  // Mount driver
  // storage.mount("mongodb", driver);
  // console.log("mongodb driver mounted");
});
// import { createStorage } from "unstorage";
// import fsDriver from "unstorage/drivers/fs-lite";

// const storage = createStorage({
//  driver: fsDriver({ base: "./tmp" }),
// });

// export async function sayHello() {
//  console.log("Hello World");
//  await storage.setItem(
//   "count",
//   (Number(await storage.getItem("count")) ?? 0) + 1,
//  );
//  return Number(await storage.getItem("count")) ?? 0;
// }

// export async function getStore() {
//  return Number(await storage.getItem("count")) ?? 0;
// }
